package controller;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import model.MyEllipse;
import model.MyPosition;
import model.MyRectangle;
import model.MyShape;
import model.TypeImage;
import view.interfaces.IAddShapeOne;
import view.interfaces.IAddShapeThree;

public class ControllerAddShapeThree implements ActionListener {

	private IAddShapeThree view;

    public ControllerAddShapeThree() { }

    public void setView(IAddShapeThree viewEntry) {
            
        this.view = viewEntry;
        
    }

    public IAddShapeThree getView() {
            
        return view;
            
    }

	@Override
	public void actionPerformed(ActionEvent e) {

		String action = e.getActionCommand();

    	if(action.startsWith("SENDADDSHAPETHREE")) {

    		if(Integer.toString(view.getValueTxtFieldWidth()).equals("") ||
    			Integer.toString(view.getValueTxtFieldHeight()).equals("") 
    			) {
    			
    			JOptionPane.showMessageDialog(null, "Vous avez omis une dimension !");
    			
    		}
    		else {
    			
    			int depth = view.getValueTxtFieldDepth();
    			int posX = view.getValueTxtFieldPositionX();
    			int posY = view.getValueTxtFieldPositionY();
    			int width = view.getValueTxtFieldWidth();
    			int height = view.getValueTxtFieldHeight();
    			Color filling = view.getValueComboBoxColorFilling();
    			Color outline = view.getValueComboBoxColorOutline();
    			int border = view.getValueTxtFieldBorderSize();
    			Boolean ironWire = view.getValueIsIronWire();
    			MyShape forme = null;
    			
	    		if(view.getValueComboBoxShapesAvailable().equals("Rectangle")) {

	    				forme = new MyRectangle(depth, 
	    							new MyPosition(posX, posY), 
	    							width, 
	    							height,
	    		    				new TypeImage<Color>(filling, outline),
	    							border, ironWire);

	    			
	    		}
	    		else if(view.getValueComboBoxShapesAvailable().equals("Ellipse")) {

	    			forme = new MyEllipse(depth, 
								new MyPosition(posX, posY), 
								width, 
								height,
			    				new TypeImage<Color>(filling, outline),
								border, ironWire);

	    		
	    		}
	    		
	    		ControllerHome.image.addShape(forme);
	    		
	    		view.hideWindowAddShape();
	    		
    		}

    	}
    	
	}
	
}
